﻿@{
    ViewBag.Title = "账户日志";
}
@section headerSection{
    <style>
        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-left: 5px;
        }
    </style>
}
<div class="animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins" style="margin-bottom: 0px;">
        <div class="ibox-content" style="padding: 5px 20px 0px 20px;">
            <div class="row row-lg">
                <div class="col-sm-12 col-sm-leftRight">
                    <!-- Example Toolbar -->
                    <div class="example">
                        <div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                            <div class="form-group" style="margin-left:0;width:120px;">
                                <input id="userName" name="userName" type="text" class="form-control" placeholder="用户名/登录名">
                            </div>
                            <div class="form-group" style="margin-top:-2px;width:220px;">
                                <select id="userUnit" name="userUnit" title="所属单位" class="form-control show-tick selectpicker" placeholder="所属单位"></select>
                            </div>
                            <div class="form-group" style="margin-top:-2px;width:120px;">
                                <select id="goldType" name="goldType" title="金币类别" class="form-control show-tick selectpicker" placeholder="金币类别">
                                    <option value="0" selected>全部</option>
                                    <option value="1">V金币</option>
                                    <option value="2">赠送币</option>
                                </select>
                            </div>
                            <div class="form-group" style="margin-top:-2px;width:120px;">
                                <select id="operatorType" name="operatorType" title="操作类别" class="form-control show-tick selectpicker" placeholder="操作类别">
                                    <option value="0" selected>全部</option>
                                    <option value="1">充值</option>
                                    <option value="2">支付</option>
                                </select>
                            </div>
                            <div class="form-group" style="width:140px;">
                                <input id="inDate" name="inDate" type="text" class="laydate-icon form-control input-sm" placeholder="起始操作日期" title="起始操作日期" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" />
                            </div>
                            <div class="form-group" style="width:140px;">
                                <input id="outDate" name="outDate" type="text" class="laydate-icon form-control input-sm" placeholder="截止操作日期" title="截止操作日期" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" />
                            </div>
                            <div class="form-group">
                                <button id="btnSearch" class="btn btn-primary" type="button"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                        </div>
                        <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true"></table>
                    </div>
                    <!-- End Example Toolbar -->
                </div>
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
</div>
@section footSection{
    <script>
        var $table, options;
        var goldManager = {
            initPage: function () {
                goldManager.initSelect();
                goldManager.bindEvent();
                goldManager.initTable();
            },
            initSelect:function(){
                $.ajax({
                    url: ctx + '/SysCommon/GetDictionaryByCode',
                    type: "post",
                    cache: false,
                    async: false,
                    data: { fieldCode: 'SysUserUnit' },
                    dataType: 'json',
                    success: function (data) {
                        if (data.Statu === 1) {
                            layer.msg(data.Msg, { icon: 5 });
                            return false;
                        }
                        var itemStr = "";
                        $.each(data.Data, function (i, item) {
                            itemStr += "<option value='" + item.code_value + "'>" + item.code_name + "</option>";
                        });
                        $('#userUnit').append(itemStr);//单个添加
                    },
                    error: function () {
                        layer.msg('数据异常~', { icon: 5 });
                    }
                });
                $('#userUnit').selectpicker({ size: 6 });
                $('#userUnit').selectpicker('refresh');
            },
            initTable: function () {
                options = {
                    url: ctx + "/AccountManager/GetGoldData",
                    cutHeight: 5,
                    toolbar: "#exampleToolbar",
                    queryParams: function (params) {
                        params = {
                            //页面大小  
                            rows: params.limit,
                            //第几页
                            page: params.offset / params.limit + 1,
                            userName: $('#userName').val(),
                            unitCode: $('#userUnit').val(),
                            goldType: $('#goldType').val(),
                            operatorType: $('#operatorType').val(),
                            inDate: $('#inDate').val(),
                            outDate: $('#outDate').val()
                        }
                        return params;
                    },
                    columns: [
                         {
                             radio: true
                         }, {
                             field: '',//第一列序号
                             title: '序号',
                             align: 'center',
                             width: 50,
                             formatter: function (value, row, index) {
                                 return index + 1;
                             }
                         }, {
                             field: 'user_name',
                             title: '用户名',
                             align: 'center'
                         }, {
                             field: 'login_name',
                             title: '登录名',
                             align: 'center'
                         }, {
                             field: 'unit_name',
                             title: '所属单位',
                             align: 'center',
                             formatter: function (value, row, index) {
                                 if (value && value.toString().length > 18)
                                    return "<span title='" + value + "'>" + value.toString().substring(0, 18) + "...</span>";
                                 else
                                     return value;
                             }
                         }, {
                             field: 'gold_type',
                             title: '金币类别',
                             align: 'center',
                             formatter: function (value, row, index) {
                                 if (value && value === 1)
                                     return "V金币";
                                 else  if (value && value === 2)
                                     return "赠送币";
                                 return "-";
                             }
                         }, {
                            field: 'BeforBuyGold',
                             title: '变动前金币',
                            align: 'center',
                            formatter: function (v, r, i) {
                                //记录是金币
                                if (r.gold_type == 1) {
                                    return r.BeforBuyGold;
                                }
                                //记录是赠币
                                if (r.gold_type == 2) {
                                    return r.BeforGiveGold;
                                }
                                return '-';
                            }
                        }, {
                             field: 'gold_num',
                             title: '变动金币数额',
                            align: 'center',
                            formatter: function (v,r,i) {
                                //支付扣减金币
                                if (r.gold_type == 1 && r.operator_type == 2) {
                                    return '<span title="' + r.Content + '">' + r.SubtractBuyGold + '</span>';
                                }
                                //支付扣减赠币
                                if (r.gold_type == 2 && r.operator_type == 2) {
                                    return '<span title="' + r.Content + '">' + r.SubtractGiveGold + '</span>';
                                }

                                //充值的直接原路返回
                                return v;
                            }
                        }, {
                            field: 'BuyGold',
                            title: '变动后金币',
                            align: 'center',
                            formatter: function (v, r, i) {
                                //记录是金币
                                if (r.gold_type == 1) {
                                    return r.BuyGold;
                                }
                                //记录是赠币
                                if (r.gold_type == 2) {
                                    return r.GiveGold;
                                }
                                return '-';
                            }
                        }, {
                             field: 'operator_type',
                             title: '操作类别',
                             align: 'center',
                             formatter: function (value, row, index) {
                                 if (value && value === 1)
                                     return "<span class='label label-primary'>充值</span>";
                                 else if (value && value === 2)
                                     return "<span class='label label-danger'>支付</span>";
                                 return "-";
                             }
                         }, {
                             field: 'create_name',
                             title: '操作人',
                             align: 'center'
                         }, {
                             field: 'create_date',
                             title: '操作时间',
                             align: 'center'
                         }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            bindEvent: function () {
                $('#btnSearch').on('click', function () {
                    $table.bootstrapTable('refresh', options);
                });
            }
        }
        $(function () {
            goldManager.initPage();
        });
    </script>
}
